package com.cskaoyan.controller;


import com.cskaoyan.bean.Ad;
import com.cskaoyan.bean.AdUpdate;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/ad")
public class AdController {

    @Autowired
    AdService adService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit,String name,String content,String sort,String order){
        ListData<Ad> listData = adService.queryList(page,limit,name,content,sort,order);
        return BaseRespVo.ok(listData);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Ad ad){
        Ad insertAd = adService.insertAd(ad);
        return BaseRespVo.ok(insertAd);
    }


    @RequestMapping("update")
    public BaseRespVo update(@RequestBody AdUpdate adUpdate){
        adService.updateAd(adUpdate);
        AdUpdate update = adService.queryAdUpdate(adUpdate.getId());
        return BaseRespVo.ok(update);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody AdUpdate adUpdate){
        adService.deleteById(adUpdate.getId());
        return BaseRespVo.ok();
    }


}
